<?php

class TransactionTest extends BaseTest
{
    public function testInsert()
    {
        $class = new \Orm\Transaction\TransactionClass();
		$class['open_id'] = $this->testStr();
		$class['uid'] = $this->testNum();
		$class['status'] = $this->testNum();
		$class['reference'] = $this->testNum();
		$class['amount'] = $this->testNum();
		$class['platform'] = $this->testStr();
		$class['platform_id'] = $this->testStr();
		$class['out_trade_no'] = $this->testStr();
		$class['payment'] = $this->testNum();


        $class->insert();
        $result_class = new \Orm\Transaction\TransactionClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['open_id'],$result_class['open_id']);
		$this->assertEquals($class['uid'],$result_class['uid']);
		$this->assertEquals($class['status'],$result_class['status']);
		$this->assertEquals($class['reference'],$result_class['reference']);
		$this->assertEquals($class['amount'],$result_class['amount']);
		$this->assertEquals($class['platform'],$result_class['platform']);
		$this->assertEquals($class['platform_id'],$result_class['platform_id']);
		$this->assertEquals($class['out_trade_no'],$result_class['out_trade_no']);
		$this->assertEquals($class['payment'],$result_class['payment']);

        return $result_class;
    }

    /**
     * @depends testInsert
     */
    public function testUpdate($class)
    {
		$class['open_id'] = $this->testStr();
		$class['uid'] = $this->testNum();
		$class['status'] = $this->testNum();
		$class['reference'] = $this->testNum();
		$class['amount'] = $this->testNum();
		$class['platform'] = $this->testStr();
		$class['platform_id'] = $this->testStr();
		$class['out_trade_no'] = $this->testStr();
		$class['payment'] = $this->testNum();


        $class->update();
        $result_class = new \Orm\Transaction\TransactionClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['open_id'],$result_class['open_id']);
		$this->assertEquals($class['uid'],$result_class['uid']);
		$this->assertEquals($class['status'],$result_class['status']);
		$this->assertEquals($class['reference'],$result_class['reference']);
		$this->assertEquals($class['amount'],$result_class['amount']);
		$this->assertEquals($class['platform'],$result_class['platform']);
		$this->assertEquals($class['platform_id'],$result_class['platform_id']);
		$this->assertEquals($class['out_trade_no'],$result_class['out_trade_no']);
		$this->assertEquals($class['payment'],$result_class['payment']);

        return $result_class;
    }

    /**
     * @depends testUpdate
     */

    public function testDelete($class)
    {
        $class->delete($class['id']);

        $result_class = new \Orm\Transaction\TransactionClass();
        $result_class->loadById($class['id']);
        $this->assertEquals(1, $result_class['is_del']);
        return $result_class;
    }


    /**
     * @depends testInsert
     */
    public static function testClean($class)
    {
        if ($class['id']) {
            $class->realDelete($class['id']);
        }
    }
}